package pab.core.service;

import java.lang.reflect.Method;

import pab.core.exception.AccountException;
import pab.core.transaction.Transaction;

public class Condition {
	protected enum LogicOperator {
		AND,
		OR
	}
	protected String prop;
	protected Object value;
	protected Method method;
	protected Condition nextCondition;
	protected LogicOperator op;
	
	public Condition(String prop, Object value) throws AccountException {
		super();
		this.prop = prop;
		try {
			if (value instanceof Boolean) {
				method = BeanUtils.getIsMethod(Transaction.class, prop);
			} else {
				method = BeanUtils.getGetMethod(Transaction.class, prop);
			}
		} catch (Exception e) {
			throw new AccountException("Boolean property \"" + prop + "\" is not accessible");
		}
		this.value = value;
	}

	public Condition and(Condition condition) {
		nextCondition = condition;
		op = LogicOperator.AND;
		return condition;
	}
	
	public Condition or(Condition condition) {
		nextCondition = condition;
		op = LogicOperator.OR;
		return condition;
	}
}
